package com.example.mybatis.dao;

import com.example.mybatis.entity.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author fanhang
 */
@Mapper
public interface UserMapper {

    @Update(" insert into t_user (id, name, age, remark) values (#{id}, #{name}, #{age}, #{remark}) ")
    int insert(User user);

    @Select(" select * from t_user where id = #{id} ")
    User findById(@Param("id") long id);

    @Select(" select * from t_user where age = #{age} ")
    List<User> findByAge(@Param("age") int age);

    /**
     * 模糊查询
     */
    @Select(" select * from t_user where age > #{age} and name like CONCAT('%', #{name}, '%') ")
    List<User> findGreaterAgeLikeName(@Param("age") int age, @Param("name") String name);
}
